package main

import "fmt"

const (
	WHITE = iota
	BLACK
	BLUE
	RED
	YELLOW
)

type Color byte

type Box struct {
	width, height, depth float64
	color Color
}

type BoxList []Box

func (b Box) Volume() float64 {
	return b.width * b.height * b.depth
}

func (b *Box) SetColor(c Color) {
	b.color = c
}

func (bl BoxList) BiggestColor() (Color, float64) {
	v := 0.00
	k := Color(WHITE)
	
	for _, b := range bl {
		if bv := b.Volume(); bv > v {
			v = bv
			k = b.color
		}
	}
	return k, v
}

func (b BoxList) PaintItBlack() {
	for i := range b {
		b[i].SetColor(BLACK)
	}
}

func (c Color) String() string {
	strings := []string{"WITHE", "BLACK", "BLUE", "RED", "YELLOW"}
	return strings[c]
}

//-------------------------------------------------------------------

type Human struct {
	name string
	age int
	phone string
}

type Student struct {
	Human
	school string
	loan float32
}

type Employee struct {
	Human
	company string
	money float32
}

func (h *Human) SayHi() {
	fmt.Printf("Hi I'm %s, you can call me on %s\n", h.name, h.phone)
}

func (h *Human) Sing(lyrics string) {
	fmt.Printf("la la la la la la la la la ... %s", lyrics)
}

func (h *Human) Guzzle(beerStein string) {
	fmt.Println("Guzzle Guzzle Guzzle ...", beerStein)
}

func (e *Employee) SayHi() {
	fmt.Printf("Hi I'm %s, I work at %s, Call me on %s", e.Human.name, e.company, e.phone)
}

func (s *Student) BorrowMoney(amount float32) {
	s.loan += amount
}

func (e *Employee) SpendSalary(amount float32) {
	e.money -= amount
}

type Men interface {
	SayHi()
	Sing(lyrics string)
	Guzzle(beerStein string)
}

type YoungChap interface {
	SayHi()
	Sing(song string)
	BorrowMoney(amount float32)
}

type ElderlyGent interface {
	SayHi()
	Sing(song string)
	SpendSalary(amount float32)
}

type Men1 interface {
	SayHi()
	Sing(lyrics string)
}

var aInt interface{}


func main() {
	
	var i int = 5
	s := "Hello world"
	// a可以存储任意类型的数值
	aInt = i
	fmt.Println(aInt)
	
	aInt = s
	fmt.Println(aInt)
	
	h := Human{"glxe", 28, "15370383786"}
	
	e := Employee{
		h,
		"dongshiyun",
		10000.00,
	}
	_ = e
	//h.SayHi()
	//e.SayHi()
	
	
	mike := Student{
		Human{"Mike", 25, "222-222-XXX"},
		"MIT",
		0.00}
	paul := Student{
		Human{"Paul", 26, "111-222-XXX"},
		"Harvard",
		100}
	sam := Employee{
		Human{"Sam", 36, "444-222-XXX"},
		"Golang Inc.",
		1000}
	tom := Employee{
		Human{"Tom", 37, "222-444-XXX"},
		"Things Ltd.",
		5000,
	}
	
	var ii Men1
	
	ii = mike
	
	ii.SayHi()
	
	
	xx := make([]Men1, 3)
	xx[0], xx[1], xx[2] = paul, sam, tom
	
	for _, v := range xx {
		v.SayHi()
	}
	
	fmt.Println()
	
	//------------------------------------------------
	
	boxes := BoxList {
		Box{4, 4, 4, RED},
		Box{10, 10, 1, YELLOW},
		Box{1, 1, 20, BLACK},
		Box{10, 10, 1, BLUE},
		Box{10, 30, 1, WHITE},
		Box{20, 20, 20, YELLOW},
	}
	
	color, f := boxes.BiggestColor()
	fmt.Println(color.String())
	fmt.Println(f)
	fmt.Printf("this is %v\n", boxes)
	
	boxes.PaintItBlack()

	fmt.Printf("this is %v\n", boxes)
	
	fmt.Printf("%s\n", "YELLOW")
	
}
